/*
 * list
 *
 *  Created on: Jan 14, 2010
 *      Author: artur
 */

#ifndef LIST_
#define LIST_

namespace util {


typedef struct l_el {
	struct l_el *prev;
	struct l_el *next;
	void *data;
} __list_element;

template <typename T>
class list
{
public:
	list();
	~list() {
	}
	int add(T&);
	int remove(__list_element *);
	void clear(void);
	T next(void);
	int size ;  // Number of elements on Stack
	void rew(void);
	void fwd(void);

protected:
	__list_element *head;
	__list_element *end;
	__list_element *pos;
};


template <typename T>
list<T>::list()
{
	pos = end = head = 0;
	size = 0;
}

template <typename T>
int list<T>::add(T& t)
{
	__list_element * elem = new __list_element;

	elem->data = (void *)t;

	if (!head)
	{
		pos = end = head = elem;
		head->next = head->prev = head;
	}
	else
	{
		elem->next = end->next;
		elem->prev = end;
		elem->next->prev = elem;
		elem->prev->next = elem;
		end = elem;
	}

	size++;
}

template <typename T>
void list<T>::rew()
{
	pos = head;
}

template <typename T>
void list<T>::fwd()
{
	pos = end;
}


template <typename T>
T list<T>::next(void)
{
//	if (pos != end)
//	{
		pos = pos->next;
//	}
	return (T)(pos->data);
}

template <typename T>
int list<T>::remove(__list_element *el)
{
}

template <typename T>
void list<T>::clear()
{
}


}

#endif /* LIST_ */
